<template>
<view>
<!--cart2.wxml-->
<form @submit="submitForm">
<view class="container">
    <view class="user-mes" @tap="enterAddressPageFun">    
        <view class="location">
            <block v-if="order.userAddress.province_name">
                <view class="user-contact">{{order.userAddress.consignee}}{{'　　'}}{{order.userAddress.mobile}}</view>
            <view class="address">{{order.userAddress.province_name + order.userAddress.city_name + order.userAddress.district_name + (order.userAddress.twon_name?order.userAddress.twon_name:'') + order.userAddress.address}}</view>            
            </block>            
            <block v-else>
                <view class="user-contact"></view> 
                <view class="address">请填写收货地址</view>                   
            </block>        
        </view>
        <view class="border-img"><image class="wh100" style="display:block" src="/static/images/tt.png"></image></view>
        <view class="update-logistics">
            <image class="arrow-rigth" src="/static/images/icon-arrowdown.png"></image>
        </view>
    </view>
    <view class="order-meg">
        <view v-for="(item, index) in order.cartList" :key="index" class="order-detail">
            <view class="goods-img">
            <image class="wh100" :src="url + '/api/goods/goodsThumImages?goods_id=' + item.goods_id + '&width=100&height=100'"></image>
            </view>
            <navigator class="order-cont" :url="'/pages/goods/goodsInfo/goodsInfo?goods_id=' + item.goods_id">
                <view class="goods-name">{{item.goods_name}}</view>
                <view class="goods-color">{{item.spec_key_name}}</view>
            </navigator>
            <view class="order-num">
                <view class="smj">￥</view>
                <view class="co-red">{{item.member_goods_price[0]}}.</view>
                <view class="smj">{{item.member_goods_price[1]}}</view>
                <view class="goods-num">x{{item.goods_num}}</view>
            </view>
        </view>
    </view>
    <view class="set-mes">
        <view v-if="order.store_prom">
            <icon type="info" size="16" color="#ff6a00"></icon>{{order.store_prom}}
        </view>
         <view class="use-item selfsubmit" style="height:280rpx;" v-if="order.cartList[0]['goods']['is_virtual'] !=2">
            <radio-group class="radio-group" @change="radioChange">
                <block v-for="(item, index) in items" :key="index">
                    <label class="radio">
                        <view>
                        <text>{{item.name}} : </text>        
                            <radio color="#ff3636" :value="index" :checked="item.checked"></radio>
                        </view>
                    </label>
                  <view class="selfsubmit-view"><text>{{item.value}}</text></view>
                </block>
            </radio-group>
        </view>
         <view class="use-item set-item " v-if="order.cartList[0]['goods']['is_virtual'] !=2 && submit">
            <view>自提时间 : </view>
            <view @tap.stop="showdate" style="width:376rpx;">
                <text>{{checkTime}}{{submit_datas.submit_text}}</text>                  
                <image class="arrow-rigth" src="/static/images/icon-arrowdown.png"></image>
            </view>
        </view>
         <view class="use-item set-item " @tap.stop="getSubmitAddress" v-if="order.cartList[0]['goods']['is_virtual'] !=2 && submit">
            <view>自提地点 : </view>
            <text style="padding-right:48rpx">{{submit_datas.submit_address}}</text>
            <image class="arrow-rigth" src="/static/images/icon-arrowdown.png"></image>
        </view>
	      <view class="invoice set-item" v-if="order.cartList[0]['goods']['is_virtual'] ==2">
            <view>预约信息</view>
            <view class="set-btn" @tap="showBespeakTpl">
                <view>填写预约信息</view>
                <image class="arrow-rigth" src="/static/images/icon-arrowdown.png"></image>
            </view>
        </view>
        <view class="invoice set-item" v-if="order.cartList[0]['goods']['is_virtual'] ==2">
            <view>选择门店</view>
            <view class="set-btn" @tap="showShopList">
                <view>{{shop_name}}</view>
                <image class="arrow-rigth" src="/static/images/icon-arrowdown.png"></image>
            </view>
        </view>
	      <view class="invoice set-item line" @tap="showInvoice">
            <view>发票信息：</view>
            <view class="set-btn">
                <view>{{text}}</view>
                <image class="arrow-rigth" src="/static/images/icon-arrowdown.png"></image>
            </view>
        </view>
      
        <view class="use-item line" v-if="order.cartList[0].goods.is_virtual != 2 && userInfo.pay_points != 0 && order.cartList[0].goods.prom_type != 8">
            <view>使用积分 : </view>
            <view>{{userInfo.pay_points}}</view>
            <!-- <input type="number" hidden="true" name="pay_points"  maxlength="20" value="{{available_integral}}" placeholder="可用积分为:{{userInfo.pay_points || 0}}" /> -->
            <view class="fr user_pay_points">
                <switch color="#ff6a00" @change="user_pay_points"></switch>
            </view>
            <!-- <button class="use-btn" form-type="submit">使用</button> -->
        </view>

    </view>
    <view class="coupon-mes line">
        <view class="coupon-title line" @tap="useCoupon" v-if="order.cartList[0].goods.prom_type != 8">
            <view class="classname">
                <view class>优惠券</view>
                <view class="coupon-num">{{order.userCouponNum.usable_num}}张可用</view>
            </view>
            <view class="set-btn">
                <view style="margin-right:36rpx">{{coupon ? coupon.coupon.name : '未使用'}}</view>
                <image class="arrow-rigth" style="top:4rpx" src="/static/images/icon-arrowdown.png"></image>
            </view>
        </view>
        <view style="font-size:26rpx">买家留言（50字）</view>
        <view class="leave-word">
            <textarea name="user_note" class="word-box" maxlength="50" @input="keyUpChangeNum" placeholder="选填：对本次交易的说明..."></textarea>
            <view class="max-word">{{maxWord}}/50</view>
        </view>
    </view>
    <!-- 价格栏 -->
    <view class="information">
        <view class="item">
            <view>商品金额</view>
            <view class="co-red">￥ {{orderPrices.goods_price}}元</view>  
        </view>
        <view class="item" v-if="orderPrices.shipping_price > 0">
            <view>配送费用</view>
            <view class="co-red">￥ {{orderPrices.shipping_price}}元</view>
        </view>
        <view class="item" v-if="orderPrices.coupon_price > 0">
            <view>使用优惠券</view>
            <view class="co-red">- ￥ {{orderPrices.coupon_price}}元</view>  
        </view>
        <view class="item" v-if="orderPrices.integral_money > 0">
            <view>使用积分</view>
            <view class="co-red">- ￥ {{orderPrices.integral_money}}元</view>  
        </view>
     
        <view class="item" v-if="orderPrices.order_prom_amount > 0">
            <view>订单优惠</view>
            <view class="co-red">- ￥ {{orderPrices.order_prom_amount}}元</view>  
        </view>
    </view>
    <view class="btn-wrap">  
        <button form-type="submit" class="tips-btn" id="submitOrder">提交订单</button>
        <view class="pay-amount">
            <view class="payable">应付金额 : </view>
            <view class="co-red">￥ {{orderPrices.order_amount}}元</view>  
        </view>
    </view>
</view>
</form>
<!-- 日期 -->
<modal catchtouchmove="catchtouchmove" class="modal" :hidden="flag" no-cancel @confirm="getTime" confirmText="确定">
    <view class="modal-content">
        <view class="time_screens">
          <view style="text-align:center;color:#45BCE8">{{year}}-{{month}}-{{day}} {{hour}}:{{minute}}</view>
          <view style="border-top:1px solid #45BCE8;height:25px;font-size:14px;">
            <view class="time-title">年</view>
            <view class="time-title">月</view>
            <view class="time-title">日</view>
            <view class="time-title">时</view>
            <view class="time-title">分</view>
          </view>
          <picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" :value="value" @change="bindChange">
              <picker-view-column class="picker-text">
              <view v-for="(item, index) in years" :key="index" style="line-height: 50px">{{item}}</view>
              </picker-view-column>
              <picker-view-column class="picker-text">
              <view v-for="(item, index) in months" :key="index" style="line-height: 50px">{{item}}</view>
              </picker-view-column>
              <picker-view-column class="picker-text">
              <view v-for="(item, index) in days" :key="index" style="line-height: 50px">{{item}}</view>
              </picker-view-column>
              <picker-view-column class="picker-text">
              <view v-for="(item, index) in hours" :key="index" style="line-height: 50px">{{item}}</view>
              </picker-view-column>
              <picker-view-column class="picker-text">
              <view v-for="(item, index) in minutes" :key="index" style="line-height: 50px">{{item}}</view>
              </picker-view-column>
          </picker-view>
        </view>
    </view>
</modal>
</view>
</template>

<script>
var app = getApp();
var request = app.globalData.request;
var util = require("../../../utils/util.js");
var common = require("../../../utils/common.js");
var md5 = require("../../../utils/md5.js");
const date = new Date();
const years = [];
const months = [];
const days = [];
const hours = [];
const minutes = [];
var thisMon = date.getMonth();
var thisDay = date.getDate() + 1;
var thisHours = date.getHours();
var thisMinutes = date.getMinutes();
var totalDay = mGetDate(date.getFullYear(), thisMon);
function mGetDate(year, month) {
  var d = new Date(year, month, 0);
  return d.getDate();
}

export default {
  data() {
    return {
      url: app.globalData.setting.url,
      resourceUrl: app.globalData.setting.resourceUrl,
      goods: null,
      //立即购买商品参数
      order: null,
      //请求的订单数据
      orderPrices: null,
      //请求的订单价格数据
      coupons: null,
      //可用的优惠券
      coupon: null,
      //已使用的优惠券     
      payWithUserMoney: true,
      //是否使用余额支付
      payWithPoints: true,
      //是否使用积分支付
      maxWord: 0,
      enterAddressPage: false,
      firstEnter: true,
      //是否第一次进入页面
      invoice_title: '',
      taxpayer: '',
      invoice_desc: '不开发票',
      text: '不开发票',
      formData: {
        pay_points: '',
        user_money: '',
        paypwd: '',
        user_note: ''
      },
      shopList: null,
      shop_id: null,
      shop_name: '选择门店',
      items: [{
        name: '快速配送',
        value: '工作日、双休日与节假日均可送货',
        checked: 'true'
      }],
      submit_datas: {
        shop_id: '',
        //自提id
        submit_text: '',
        //页面展示自提时间
        submit_address: '',
        //页面展示自提地点
        name: '',
        //自提人
        mobile: '',
        //自提联系方式
        time: '' //自提时间

      },
      submit: false,
      is_set: false,
      submit_heigth_css: 240,
      selected: 0,
      checkTime: date.getFullYear() + "-" + thisMon + "-" + thisDay + " " + thisHours + ":" + thisMinutes,
      //---时间控件参数
      flag: true,
      years: years,
      year: date.getFullYear(),
      months: months,
      month: thisMon,
      days: days,
      day: thisDay,
      value: [1, 0, thisDay - 1, thisHours, thisMinutes],
      hours: hours,
      hour: thisHours,
      minutes: minutes,
      minute: thisMinutes,
      shoppingcard_id: 0,
      weekDay: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
      userInfo: "",
      shop_list: "",
      available_integral: "",
      available_balance: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    var that = this;
    var date = this.year + "/" + this.month + "/" + this.day;
    var d = new Date(date);
    var weekDay = this.weekDay;
    var day = weekDay[d.getDay()];

    if (options.shoppingcard_id) {
      that.setData({
        shoppingcard_id: "_" + options.shoppingcard_id
      });
    }

    this.setData({
      goods: options,
      'submit_datas.submit_text': ' 【' + day + '】',
      'submit_datas.time': this.year + '-' + this.month + '-' + this.day + ' ' + this.hour + ':' + this.minute
    });
    this.requestCart2();
    this.requestInvoice(); //可用余额实时刷新

    var that = this;
    app.globalData.getUserInfo(function (userInfo) {
      that.setData({
        userInfo: userInfo
      });
    }, true, false); //加载积分使用配置

    app.globalData.getConfig(function (res) {
      var is_use = common.getConfigByName(res.config, 'is_use_integral');

      if (0 == is_use) {
        that.setData({
          'userInfo.pay_points': 0
        });
      }
    });
  },
  //重新加载数据
  onShow: function () {
    this.setData({
      order: this.order
    });

    if (this.enterAddressPage) {
      this.enterAddressPage = false;
      var address = uni.getStorageSync('cart:cart2:address');

      if (address !== '') {
        uni.removeStorageSync('cart:cart2:address');
      }

      this.requestCart2(address); //改变地址要重新请求数据
    } else if (!this.firstEnter && this.checkAddressList()) {
      var conponUse = uni.getStorageSync('cart:cart2:cid');
      this.setData({
        coupon: conponUse,
        text: this.text
      });
      this.calculatePrice(); //其他操作离开页面要重新计算价格
    }

    this.firstEnter = false;

    if (this.is_set) {
      this.is_set = false;
      this.setData({
        'submit_datas.submit_address': this.submit_datas.submit_address
      });
    }
  },
  onUnload: function () {
    var conponUse = uni.getStorageSync('cart:cart2:cid');

    if (conponUse) {
      uni.removeStorageSync('cart:cart2:cid');
    }
  },
  methods: {
    /** 获取用户收货地址 */
    getDefaultAddress: function () {
      var that = this;
      request.get('/api/User/ajaxAddressList', {
        success: function (res) {
          if (res.data.result.length > 0) {
            var address = res.data.result[0] || null;
            that.setData({
              'order.userAddress': address
            });
            that.getShopList();

            if (that.checkAddressList()) {
              that.calculatePrice();
            }
          } else {
            that.checkAddressList();
          }
        }
      });
    },
    //获取微信地址并保存为默认地址
    submitAddress: function (data) {
      var that = this;
      var address = {
        address: data.detailInfo,
        city: 0,
        city_name: data.cityName,
        consignee: data.userName,
        district: 0,
        district_name: data.countyName,
        is_default: 1,
        mobile: data.telNumber,
        province: 0,
        province_name: data.provinceName,
        twon: 0,
        twon_name: ''
      };

      if (!app.globalData.validatemobile(address.mobile)) {
        return;
      }

      request.post('/api/user/addAddress', {
        data: address,
        failRollback: false,
        successReload: true,
        success: function (res) {
          if (res.data.status == 1) {
            address.address_id = res.data.result;
            that.setData({
              'order.userAddress': address
            });
          }
        }
      });
    },

    /** 发票 */
    requestInvoice: function () {
      var that = this;
      request.get('/api/cart/invoice', {
        failRollback: false,
        successReload: true,
        success: function (res) {
          if (res.data.result.invoice_title) {
            var text = res.data.result.invoice_desc == '不开发票' ? '不开发票' : '纸质 ( ' + res.data.result.invoice_title + '-' + res.data.result.invoice_desc + ' )';
            that.setData({
              text: text,
              invoice_title: res.data.result.invoice_title,
              invoice_desc: res.data.result.invoice_desc,
              taxpayer: res.data.result.taxpayer
            });
          }
        }
      });
    },
    requestCart2: function (address) {
      var that = this;
      var data;

      if (this.goods.action) {
        //商品立即购买跳转
        data = {
          goods_id: this.goods.goods_id,
          shoppingcard_id: this.shoppingcard_id,
          item_id: this.goods.item_id,
          goods_num: this.goods.goods_num,
          action: this.goods.action
        };
      }

      request.get('/api/cart/cart2', {
        failRollback: true,
        data: data,
        success: function (res) {
          var j = 0;

          for (var i of res.data.result.cartList) {
            res.data.result.cartList[j].member_goods_price = parseFloat(i.member_goods_price).toFixed(2).toString().split('.');
            j++;
          }

          console.log('================================', res.data.result.cartList[0]);
          that.setData({
            order: res.data.result
          });

          if (res.data.result.userCouponNum.usable_num > 0) {
            that.setData({
              coupons: res.data.result.userCartCouponList
            });
          } else {
            that.setData({
              coupons: []
            });
          }

          if (address) {
            that.setData({
              'order.userAddress': address
            });
            that.getShopList();

            if (that.checkAddressList()) {
              that.calculatePrice();
            }
          } else if (uni.getStorageSync('goodsInfo:goodsInfo:address')) {
            that.setData({
              'order.userAddress': uni.getStorageSync('goodsInfo:goodsInfo:address')
            });
            that.getShopList();
            uni.removeStorageSync('goodsInfo:goodsInfo:address');

            if (that.checkAddressList()) {
              that.calculatePrice();
            }
          } else {
            that.getDefaultAddress();
          }
        },
        failStatus: function (res) {
          if (res.data.status == 0) {
            uni.showModal({
              title: res.data.msg,
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  uni.navigateBack();
                }
              },
              fail: function () {
                uni.navigateBack();
              }
            });
          } else if (res.data.status == -1) {
            that.setData({
              order: null
            });
            that.checkAddressList();
          }

          return false;
        }
      });
    },
    checkAddressList: function () {
      var that = this;

      if (!that.order || that.order.userAddress == null) {
        uni.showModal({
          title: '请先填写或选择收货地址~',
          success: function (res) {
            if (res.confirm) {
              that.enterAddressPageFun();
            } else {
              uni.navigateBack();
            }
          },
          fail: function () {
            uni.navigateBack();
          }
        });
        return false;
      }

      return true;
    },
    //判断获取预约门店还是获取自提点
    getShopList: function () {
      var that = this;
      uni.authorize({
        scope: 'scope.userLocation',
        success: function (res) {
          uni.getLocation({
            type: 'wgs84',

            success(res2) {
              that.order.cartList[0]['goods']['is_virtual'] == 2 ? that.requestShopList(res2) : that.getSubmitAddressDatas(res2);
            }

          });
        }
      });
    },
    requestShopList: function (res) {
      var that = this;
      var datas = that.order.userAddress;
      request.post('/Home/Api/shop', {
        data: {
          province_id: datas.province,
          city_id: datas.city,
          district_id: datas.district,
          shop_address: '',
          //datas.address
          longitude: res.longitude,
          latitude: res.latitude
        },
        successReload: true,
        success: function (res) {
          console.log('shopList', res);

          if (res.data.result.length == 0) {
            that.setData({
              shop_list: null,
              shop_id: null,
              shop_name: '选择门店'
            });
            uni.showModal({
              title: '下单提示',
              content: '当前地址附近没有门店',
              showCancel: false
            });
            return;
          }

          that.setData({
            shop_list: res.data.result,
            shop_id: res.data.result[0].shop_id,
            shop_name: res.data.result[0].shop_name
          });
        }
      });
    },

    /** 显示发票信息 */
    showInvoice: function () {
      uni.navigateTo({
        url: '../../cart/invoice/invoice'
      });
    },
    keyUpChangePay1: function (e) {
      this.setData({
        payWithUserMoney: e.detail.value.length > 0 ? false : true
      });
    },
    // keyUpChangePay2: function (e) {
    //     this.setData({
    //         payWithPoints: e.detail.value.length > 0 ? false : true
    //     });
    // },
    keyUpChangeNum: function (e) {
      this.setData({
        maxWord: e.detail.value.length
      });
    },

    /** 请求计算价格 */
    calculatePrice: function (formData, submitOrder) {
      var that = this;

      if (typeof formData == 'undefined') {
        formData = that.formData;
      } else {
        that.formData = formData;
      }

      var pwd = formData.paypwd ? md5('TPSHOP' + formData.paypwd) : '';
      var postData;
      var submitTime = '';

      if (this.submit_datas.time != '') {
        submitTime = this.submit_datas.time.replace(/-/g, '/');
        submitTime = Date.parse(new Date(submitTime)) / 1000;
      }

      if (!!!that.order.userAddress) {
        return app.globalData.showTextWarining('请添加地址', function () {
          that.setData({
            enterAddressPage: true
          });
          uni.navigateTo({
            url: '../../user/address_list/address_list'
          });
        });
      }

      if (this.goods.action) {
        postData = {
          address_id: that.order.userAddress.address_id,
          invoice_title: that.invoice_title ? that.invoice_title : '',
          taxpayer: that.taxpayer ? that.taxpayer : '',
          invoice_desc: that.invoice_desc ? that.invoice_desc : '',
          pay_points: formData.pay_points ? formData.pay_points : this.available_integral,
          user_money: formData.user_money ? formData.user_money : 0,
          //payPwd: pwd,
          //pay_pwd: pwd,
          act: submitOrder ? 'submit_order' : 'order_price',
          user_note: formData.user_note,
          coupon_id: that.coupon ? that.coupon.id : '',
          goods_id: this.goods.goods_id,
          item_id: this.goods.item_id,
          goods_num: this.goods.goods_num,
          action: this.goods.action,
          shop_id: this.submit ? this.submit_datas.shop_id : '',
          take_time: submitTime,
          consignee: this.submit ? this.submit_datas.name : '',
          mobile: this.submit ? this.submit_datas.mobile : '',
          from_terminal: 'miniapp',
          shopping_card_ids: this.shoppingcard_id
        };
        postData = submitOrder ? that.getBespeakFormData(postData) : postData;
      } else {
        postData = {
          address_id: that.order.userAddress.address_id,
          invoice_title: that.invoice_title ? that.invoice_title : '',
          taxpayer: that.taxpayer ? that.taxpayer : '',
          invoice_desc: that.invoice_desc ? that.invoice_desc : '',
          pay_points: formData.pay_points ? formData.pay_points : 0,
          user_money: formData.user_money ? formData.user_money : 0,
          //payPwd: pwd,
          //pay_pwd: pwd,
          act: submitOrder ? 'submit_order' : 'order_price',
          user_note: formData.user_note,
          coupon_id: that.coupon ? that.coupon.id : '',
          shop_id: this.submit ? this.submit_datas.shop_id : '',
          take_time: submitTime,
          consignee: this.submit ? this.submit_datas.name : '',
          mobile: this.submit ? this.submit_datas.mobile : '',
          from_terminal: 'miniapp',
          shopping_card_ids: this.shoppingcard_id
        };
      }

      request.post('/api/cart/cart3', {
        data: postData,
        success: function (res) {
          if (res.data.result.integral_msg) {
            app.globalData.showTextWarining(res.data.result.integral_msg);
            that.setData({
              available_integral: res.data.result.pay_points
            });
          }

          if (!submitOrder) {
            that.setData({
              orderPrices: res.data.result
            });
            return;
          }

          uni.removeStorageSync('bespeakFormData');
          uni.removeStorageSync('bespeak_template_unit');
          var order_type = that.order.cartList[0].prom_type;

          if (that.submit) {
            order_type = 9;
          }

          if (that.orderPrices.order_amount <= 0) {
            uni.setStorageSync('order:order_list:update', true);
            var url_param = that.order.cartList[0]['goods']['is_virtual'] == 2 ? '&goods_name=' + that.order.cartList[0]['goods']['goods_name'] + '&take_time=' + postData.take_time : '';
            uni.redirectTo({
              url: '/pages/payment/payment/payment?order_sn=' + res.data.result + '&order_amount=' + that.orderPrices.total_amount + '&order_type=' + order_type + url_param
            });
          } else {
            var params = that.order.cartList[0]['goods']['is_virtual'] == 2 ? {
              order_sn: res.data.result,
              order_type: 7,
              goods_name: that.order.cartList[0]['goods']['goods_name'],
              take_time: postData.take_time
            } : {
              order_sn: res.data.result,
              order_type: order_type
            };
            var url = '/pages/cart/cart4/cart4?' + util.Obj2Str(params);
            uni.redirectTo({
              url: url
            });
          }
        },
        failStatus: function (res) {
          if (res.data.msg == '请先设置支付密码') {
            uni.showModal({
              title: '请先设置支付密码',
              success: function (res) {
                if (res.confirm) {
                  uni.navigateTo({
                    url: '/pages/user/userinfo/userinfo'
                  });
                } else {
                  uni.navigateBack();
                }
              },
              fail: function () {
                uni.navigateBack();
              }
            });
          } else if (res.data.status == -5) {
            that.setData({
              available_integral: ''
            });
          } else if (res.data.status == -6) {
            that.setData({
              available_balance: ''
            });
          }
        }
      });
    },
    getSubmitAddressDatas: function (res) {
      var that = this;
      var datas = that.order.userAddress;
      request.post('/Home/Api/shop', {
        data: {
          province_id: datas.province,
          city_id: datas.city,
          district_id: datas.district,
          shop_address: '',
          //datas.address
          longitude: res.longitude,
          latitude: res.latitude
        },
        successReload: true,
        success: function (res) {
          if (res.data.result.length > 0) {
            var items = [{
              name: '快速配送',
              value: '工作日、双休日与节假日均可送货',
              checked: 'true'
            }, {
              name: '上门自提',
              value: '选择自提上门点并支付订单>收到提货短信>到自提点提货'
            }];
            that.setData({
              items: items,
              'submit_datas.shop_id': res.data.result[0].shop_id,
              'submit_datas.submit_address': res.data.result[0].shop_name,
              'submit_datas.name': datas.consignee,
              'submit_datas.mobile': datas.mobile,
              submit_heigth_css: 240
            });
          } else {
            that.setData({
              items: [{
                name: '快速配送',
                value: '工作日、双休日与节假日均可送货',
                checked: 'true'
              }],
              submit_heigth_css: 120,
              submit: false
            });
          }
        }
      });
    },
    radioChange: function (e) {
      if (parseInt(e.detail.value) == 1) {
        this.setData({
          submit: true
        });
        this.calculatePrice();
      } else {
        this.setData({
          submit: false //'submit_datas.shop_id':''

        });
        this.calculatePrice();
      }
    },
    showdate: function () {
      this.setData({
        flag: false
      });
    },

    getSubmitAddress() {
      uni.navigateTo({
        url: '../../cart/submit_address/submit_address?selected=' + this.selected + '&datas=' + JSON.stringify(this.order.userAddress)
      });
    },

    /** 提交订单 */
    submitForm: function (e) {
      if (this.order.cartList[0]['goods']['is_virtual'] == 2 && !this.shop_id) {
        uni.showModal({
          title: '操作提示',
          content: '请先选择门店',
          showCancel: false
        });
        return;
      }

      var submitOrder = e.detail.target.id == 'submitOrder' ? true : false;
      this.calculatePrice(e.detail.value, submitOrder);
    },

    /** 使用优惠券 */
    useCoupon: function () {
      if (this.order.couponNum <= 0) {
        return app.globalData.showTextWarining("无可用优惠券");
      }

      console.log(this.coupon);
      var params = {
        lid: this.coupon ? this.coupon.id : '0'
      };
      uni.navigateTo({
        url: '/pages/user/checkcoupon/checkcoupon?' + util.Obj2Str(params)
      });
    },
    enterAddressPageFun: function () {
      this.enterAddressPage = true;
      uni.navigateTo({
        url: '/pages/user/address_list/address_list?operate=select'
      });
    },

    /**     预约模板              */
    showBespeakTpl: function () {
      uni.setStorage({
        key: 'bespeak_template_unit',
        data: this.order.cartList[0]['goods']['bespeak_template_unit'],
        success: function (res) {
          uni.navigateTo({
            url: './cart2Bespeak/cart2Bespeak'
          });
        }
      });
    },
    //获取填写的预约信息
    getBespeakFormData: function (data) {
      if (this.order.cartList[0]['goods']['is_virtual'] != 2) {
        return data;
      }

      var datas = uni.getStorageSync('bespeakFormData');

      if (!datas) {
        return data;
      }

      var form_data = datas.form_data;

      for (var k in form_data) {
        if (typeof form_data[k] == 'object') {
          form_data[k].forEach(function (i, s) {
            data[k + '[' + s + ']'] = i;
          });
        } else {
          data[k] = form_data[k];
        }
      }

      data['shop_id'] = this.shop_id;
      return data;
    },
    showShopList: function () {
      if (!this.shop_list) {
        uni.showModal({
          title: '操作提示',
          content: '当前地址附近没有门店',
          showCancel: false
        });
        return;
      }

      uni.navigateTo({
        url: './shopList/shopList?datas=' + JSON.stringify(this.shop_list)
      });
    },

    /** 日期插件s */
    showModel: function (e) {
      this.setData({
        flag: false
      });
    },
    getTime: function (e) {
      var times = this.year + "-" + this.month + "-" + this.day;
      var date_time_picker_mask = times;
      var date = date_time_picker_mask.replace(/-/g, '/');
      var d = new Date(date);
      var weekDay = this.weekDay;
      var day = weekDay[d.getDay()];
      this.setData({
        flag: true,
        checkTime: times + " " + this.hour + ":" + this.minute,
        'submit_datas.submit_text': ' 【' + day + '】',
        'submit_datas.time': times + " " + this.hour + ":" + this.minute
      });
    },
    bindChange: function (e) {
      const val = e.detail.value;
      this.setData({
        year: this.years[val[0]],
        month: this.months[val[1]],
        day: this.days[val[2]],
        hour: this.hours[val[3]],
        minute: this.minutes[val[4]]
      });
      var totalDay = mGetDate(this.year, this.month);
      var changeDate = [];

      for (let i = 1; i <= totalDay; i++) {
        var k = i;

        if (0 <= i && i < 10) {
          k = "0" + i;
        }

        changeDate.push(k);
      }

      this.setData({
        days: changeDate
      });
    },

    /** 日期插件e */
    catchtouchmove: function () {
      return;
    },
    //使用积分
    user_pay_points: function (d) {
      var e = Object();

      if (d.detail.value) {
        e.pay_points = this.userInfo.pay_points;
      } else {
        e.pay_points = 0;
      }

      this.setData({
        available_integral: e.pay_points
      });
      this.calculatePrice(e);
    }
  }
};
</script>
<style>
/* cart2.wxss */
.container{
    padding-bottom: 100rpx;
}
.user-mes{
    position: relative;
    background-color: #fff;
    font-size: 32rpx;
    color: #444;
    border-top: 1rpx solid #f3f3f3;
}
.user-contact{
  color: #333333;
  font-size: 30rpx;
  font-weight: 500;
}
.location{
    position: relative;
    padding:20rpx 80rpx 35rpx 30rpx;
}
.address{
    font-size: 26rpx;
    margin-top: 35rpx;
    color: #999999;
}
.pos-icon{
    position: absolute;
    left: 30rpx;
    bottom: 35rpx;
    width: 32rpx;
    height: 32.5rpx;
    padding-left:15rpx;
}
.border-img{
    width: 100%;
    height: 10rpx;
}
.update-logistics{
    position: absolute;
    right:20rpx;
    top:-16rpx;
    width: 80rpx;
    height: 148rpx;
    display: flex;
    align-items: center;
    justify-content: center;
}
.arrow-rigth{
    width: 26rpx;
    height: 26rpx; 
    position:absolute;
    right:0;
    top:40rpx;
}
.order-meg{
    font-size: 28rpx;
}
.order-detail{
    padding: 24rpx 0;
    border-bottom: 1px solid #f3f3f3;
    color: #777;
    min-height: 120rpx;
    background-color:#fff;
    overflow: hidden;
}
.goods-img{
    float: left;
    width: 180rpx;
    height: 180rpx;
    margin:0 20rpx; 
}
.order-cont{
    float: left;
    width: 510rpx;
}
.goods-name{
    max-height: 60rpx;
    line-height: 30rpx;
    margin-bottom: 16rpx;
    font-size:26rpx;
    width: 490rpx;
    display: -webkit-box;
    word-break: break-all;
    -webkit-box-orient: vertical;
    -webkit-line-clamp:1;   
    overflow: hidden;
    text-overflow:ellipsis;
    height: 30rpx;
    color: #1d1d1d;
}
.goods-color{
    font-size: 24rpx;
    color: #999999;
    display: -webkit-box;
    word-break: break-all;
    -webkit-box-orient: vertical;
    -webkit-line-clamp:2;  
    overflow: hidden;
    text-overflow:ellipsis;
    height: 60rpx;
}
.order-num{
    float: right;
    font-size: 24rpx;
    margin-right: 20rpx;
    line-height: 42rpx;
    width: 510rpx;
    margin-top: 32rpx;
}
.order-num view{
  float: left;
  font-weight: bold;
}
.goods-num{
  text-align: right;
  font-weight: normal!important;
  color: #1b1b1b;
  float: right!important;
}
.line{
    border-bottom: 2rpx solid #f3f3f3;
}
.set-mes{
    background-color: #fff;
    padding: 0 20rpx;
    font-size: 30rpx;
    color: #444;
    border-top:10px solid #ffffff;
}
.set-mes>view{
    display: flex;
    align-items: center;
    height: 100rpx;
    font-size: 26rpx;
}
.set-item{
    justify-content: space-between;
    font-size: 26rpx;
    position: relative;
    margin-top:-32rpx;
    padding-right: 40rpx;
}
.set-btn{
    display: flex;
    font-size: 24rpx;
}
.set-mes input{
    width: 380rpx;
    height: 50rpx;
    line-height: 50rpx;
    border:1px solid #f3f3f3;
    margin-left:10rpx;
    padding-left:5px;
}
.use-btn{
    width: 100rpx;
    height: 50rpx;
    margin-left: 82rpx;
    line-height: 50rpx;
    text-align: center;
    background-color: #ff6a00;
    color: #fff;
    font-size:26rpx;
    border-radius:10rpx;
}
.coupon-mes{
    margin-bottom: 15rpx;
    padding:0 28rpx 0rpx 20rpx;
    background-color: #fff;
    font-size: 30rpx;
    color: #444;
    padding-top:10px;
}
.coupon-title{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 92rpx;
    font-size:26rpx;
    margin-bottom:15rpx;
}
.coupon-title>view{
    display: flex; 
    position: relative;   
}
.smj{
  display: inline-block;
  min-width: 5rpx!important;
  padding: 0!important;
  color: #ff6a00;
  font-size: 24rpx;
  line-height: 48rpx;
}
.coupon-num{
    height: 36rpx;
    margin-left: 20rpx;
    padding: 0 16rpx;
    line-height: 36rpx;
    text-align: center;
    background-color: #ff6a00;
    color: #fff;
    font-size: 24rpx;
}
.leave-word{
    position: relative;
    margin: 25rpx 0;
    font-size: 24rpx;
}
.word-box{
    width:710rpx;
    padding:15rpx 15rpx;
    height:140rpx;
    line-height:40rpx;
    box-sizing:border-box;
    background-color:#f5f5f5;
}
.co-red{
  font-weight: bold;
  float: left;
  min-width: 5rpx;
  font-size: 30rpx;
}
.mb-15{
  margin-bottom: 15rpx;
}
.max-word{
    position: absolute;
    right:20rpx;
    bottom:10rpx;
    color: #999999;
}
.information{
    padding: 0 20rpx;
    background-color: #fff;
    margin-bottom: 15rpx;
}
.information .item{
    display: flex;
    justify-content: space-between;
    height: 60rpx;
    line-height: 60rpx;
    font-size: 26rpx;
    color: #777;
}
.btn-wrap{
    height: 100rpx;
    background-color: #fff;
    position: fixed;
    width: 750rpx;
    bottom: 0;
    z-index: 99;
}
.tips-btn{
    float: right;
    width: 200rpx;
    height: 100rpx;
    line-height: 100rpx;
    text-align: center;
    font-size: 30rpx;
    color: #fff;
    background-color: #ff6a00;
}
.pay-amount{
    float: right;
    display: flex;
    align-items: center;
    height: 100rpx;
    font-size: 26rpx;
    margin-right: 40rpx;
}
.payable{
    color: #444;
    margin-right: 20rpx;
}
/* 物流列表弹框 */
.shipping-modal{
    z-index: 20;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    overflow-y: hidden;
    color: #666666;
    background-color: white;
}
.shipping-nav{
    text-align: center;
    font-size: 35rpx;
    padding-top: 30rpx;
}
.shipping-list{
    padding: 20rpx 30rpx 40rpx;
    font-size: 28rpx;
}
.shipping-item{
    display: block;
    padding: 20rpx 0;
}
.shipping-btn{
    width: 100%;
    color: white;
    background-color: #ff6a00;
    line-height: 90rpx;
    text-align: center;
    font-size: 40rpx;
}
.invoice-text{
    color:red;font-size:12px;
}

.selfsubmit radio{
    float:right;
    transform:scale(0.85);
}
.selfsubmit-view{
  margin-top: 30rpx;
  padding-bottom:20rpx;
  margin-bottom: 10rpx;
  border-bottom:1px solid #f3f3f3;
  font-size: 24rpx;
}
.selfsubmit-view text{
    color:#777;
}
.radio-group{
    width:100%;
    font-size: 26rpx;
}

/** 日期插件s */

.kouviewList{
    background-color: #f5f5f5;
}
.kouview{
  height:170px;
    margin-top:5px;
 
}
.kouviews{
  height:150px;
    margin-top:5px;
 
}
.time-title{
  float:left;width:20%;text-align:center;color:#45BCE8
}
.picker-text{
  text-align:center;
}
/** 日期插件e */

.user_pay_points{
  position: absolute;
  right: 20rpx;
}
</style>